home *** CD-ROM | disk | FTP | other *** search
- /*
- ** MUI Helper Functions of MadCat!
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- #include <proto/locale.h>
-
- #include <libraries/gadtools.h>
-
- #include "include/mui.h"
-
- struct Locale *locale = NULL;
-
-
- #ifdef __PPC__
- /* for some reason inline version of this function doesn't work well */
- /* so this is the vararg stub for MUI_NewObjectA */
- Object *MUI_NewObject(char *classname, Tag tag1,...)
- {
- ULONG mav[50];
- va_list tags;
- int i=0;
-
- mav[i] = tag1;
- if(mav[i] != TAG_DONE)
- {
- va_start(tags, tag1);
- mav[++i] = va_arg(tags, ULONG);
- i++;
- while(i<50)
- {
- mav[i] = va_arg(tags, ULONG);
- if(mav[i] == TAG_DONE) break;
- mav[++i] = va_arg(tags, ULONG);
- i++;
- }
- va_end(tags);
- }
- return(MUI_NewObjectA(classname, (struct TagItem *)&mav));
- }
-
- /* ppc passes varargs on both registers and stack, so this is necessary */
- ULONG DoSuperNew(struct IClass *cl, Object *obj, ...)
- {
- ULONG mav[50];
- ULONG ret;
- va_list tags;
- struct opSet myopSet;
- int i=0;
-
- va_start(tags, obj);
- while(i<50)
- {
- mav[i] = va_arg(tags, ULONG);
- if(mav[i] == TAG_DONE) break;
- mav[i+1] = va_arg(tags, ULONG);
- if(mav[i] == TAG_MORE) break;
- i += 2;
- }
- va_end(tags);
-
- myopSet.MethodID = OM_NEW;
- myopSet.ops_AttrList = (struct TagItem *) &mav;
- myopSet.ops_GInfo = NULL;
- ret = DoSuperMethodA(cl, obj, (APTR)&myopSet);
-
- return ret;
- }
- #else
- ULONG __stdargs DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...)
- {
- return(DoSuperMethod(cl,obj,OM_NEW,&tag1,NULL));
- }
- #endif
-
-
- Object *maketmenu(const UBYTE *msg)
- {
- char *title = (char *)msg;
-
- if(title[1]==0)
- return(MenuitemObject,
- MUIA_Menuitem_Title, title+2,
- MUIA_Menuitem_Shortcut, title,
- MUIA_Menuitem_Toggle, TRUE,
- MUIA_Menuitem_Checkit, TRUE,
- End);
- else
- return(MenuitemObject,
- MUIA_Menuitem_Title, title,
- MUIA_Menuitem_Toggle, TRUE,
- MUIA_Menuitem_Checkit, TRUE,
- End);
- }
-
-
- Object *makemenu(const UBYTE *msg)
- {
- char *title = (char *)msg;
-
- if(msg==NULL) return(MenuitemObject,MUIA_Menuitem_Title,NM_BARLABEL,End);
-
- if(title[1]==0)
- return(MenuitemObject,
- MUIA_Menuitem_Title, title+2,
- MUIA_Menuitem_Shortcut, title,
- End);
- else
- return(MenuitemObject,MUIA_Menuitem_Title,title,End);
- }
-
-
- Object *maketoggle(const UBYTE *msg, Object **tog)
- {
- Object *obj,*obj2;
-
- obj = HGroup,
- Child, obj2 = ImageObject,
- ButtonFrame,
- MUIA_Background, MUII_ButtonBack,
- MUIA_InputMode, MUIV_InputMode_Toggle,
- MUIA_ShowSelState, FALSE,
- MUIA_CycleChain, 1,
- MUIA_Image_Spec, "6:15",
- End,
- Child, TextObject,
- MUIA_Text_Contents, (char *)msg,
- End,
- End;
-
- if(obj) {
- *tog = obj2;
- return(obj);
- } else
- return(NULL);
- }
-
-
- int mui_classes_setup(muiclass mcl[])
- {
- int i=0;
- struct MUI_CustomClass *tmp;
-
- while(mcl[i].supername)
- {
- tmp = MUI_CreateCustomClass(NULL, mcl[i].supername, NULL, mcl[i].datasize, mcl[i].dispatcher);
- if(!tmp) return 0;
- *mcl[i].ptr = tmp;
- i++;
- }
- return 1;
- }
-
-
- void mui_classes_cleanup(muiclass mcl[])
- {
- int i=0;
-
- while(mcl[i].supername)
- {
- if(*mcl[i].ptr) MUI_DeleteCustomClass(*mcl[i].ptr);
- i++;
- }
- }
-
-
- void SPrintF(char *outstr, char *fmtstr, ...)
- {
- struct Hook hook;
- #ifdef __PPC__
- va_list ap;
- ULONG arg[32];
- int args = 0, i;
-
- for (i=0; fmtstr[i] != '\0'; i++) {
- if (fmtstr[i] == '%' && fmtstr[i+1] != '%') args++;
- }
-
- va_start(ap, fmtstr);
- for (i=0; i<args; i++) {
- arg[i] = va_arg(ap, ULONG);
- }
- va_end(ap);
- #endif
-
- InitHook(&hook, putChar, outstr);
-
- #ifdef __PPC__
- FormatString(locale, fmtstr, &arg[0], &hook);
- #else
- FormatString(locale, fmtstr, &fmtstr+1, &hook);
- #endif
- }
-
-
- #ifdef __MORPHOS__
- static void putChar_gate(void)
- {
- struct Hook *hook = (struct Hook *)REG_A0;
- char c = (char)REG_A1;
- #else
- void SAVEDS ASM putChar(REG(a0, struct Hook *hook), REG(a1, char c), REG(a2, struct Locale *locale))
- {
- #endif
- char **tmp;
-
- ((char *)hook->h_Data)[0] = c;
- tmp = (char **)(&hook->h_Data);
- (*tmp)++;
- }
-